import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
  state: () => ({
    userInfo: {
      "user_id":null,
      "phone": "",
      "password": null,
      "username": "",
      "gender": 0,
      "birth_date": "",
      "avatar": null,
      "status": 1,
      "register_time": "",
      "last_login_time": "",
      "update_time": "",
      "code": null,
      "count":0,
      saTokenInfo: {
        tokenName: '',
        tokenValue: '', // 令牌值（核心标识）
        loginId: '', // 关联的用户ID（与user_id对应）
        isLogin: false, // 是否处于登录状态
        loginType: '',
        tokenTimeout: -1,
        sessionTimeout: -1
      },
    },
    "defaultPatient":{
      patient_id:null,
      user_id:null,
      name:	'11',
      id_card:	'11',
      gender:	null,
      birth_date:'',
      phone:	'',
      relationship:	'',
      is_default:1,
      status:	null,
      create_time:	'',
      update_time:	'',
      height:null,
      weight:null,
      blood_type:'',



    },
  }),

  actions: {
    setUserInfo(userInfo) {
      this.userInfo = userInfo
      this.saTokenInfo.isLogin = true
    },
    getDefaultPatient(){
      return this.defaultPatient
    },
    setDefaultPatient (patient) {
      this.userInfo.defaultPatient = patient
    },
  },

  persist: {
    enabled: true,
    strategies: [
        {
            key: 'userInfo',
            storage: localStorage,
        }
    ]
  }
})
